import React from 'react'
import {getStorage,removeStorage } from'../../redux/login/util'
import { withRouter } from 'react-router-dom'
import { connect } from 'react-redux'
import { WXloginUrl1,wxBindState } from '..//../redux/login/login'
@withRouter
@connect(
state=>state.home,
   {WXloginUrl1,wxBindState}
)

class AuthRoute extends React.Component{
	constructor(){
		super();
		this.state = {
			code:''
		}
	}
	componentDidMount() {
		console.log(this.props)
		console.log( this.GetQueryString('code'))
		if(!getStorage('user')){
			this.props.WXloginUrl1(this.GetQueryString('code'))
			this.props.history.push('/login/1')
		}else{
			this.props.wxBindState(this.GetQueryString('code'))
			let uesr =JSON.parse(getStorage('user'));
			let time = new Date().toLocaleDateString();
			time = time.replace(/[/]/g,'')
			let time1 = parseInt(time-uesr.time);
			 if(time1 >= 1 ){
				 removeStorage('user');
			 }else{
				 
			 }	
		}		 
	}
	GetQueryString(name)
{
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     var r = window.location.search.substr(1).match(reg);//search,查询？后面的参数，并匹配正则
     if(r!=null)return  unescape(r[2]); return null;
}
	render(){
		return null
	}

}
export default AuthRoute  